package l1j.opqlo.Server.Data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.opqlo.List.WeaponArmorLV;
import l1j.server.DatabaseFactory;
import l1j.server.server.utils.SQLUtil;

/** 武防升級作業員 **/
public class WeaponArmorLevelUp {

	private static final Logger _log = Logger
			.getLogger(WeaponArmorLevelUp.class.getName());
	private static WeaponArmorLevelUp _instance;
	private static HashMap<Integer, WeaponArmorLV> _map;

	public static WeaponArmorLevelUp getInstance() {
		if (_instance == null) {
			_instance = new WeaponArmorLevelUp();
		}
		return _instance;
	}

	public WeaponArmorLevelUp() {
		_map = new HashMap<Integer, WeaponArmorLV>();
		this.load();
	}

	public boolean checkTemp(final int itemId) {
		return _map.containsKey(itemId);
	}

	public WeaponArmorLV getLvUpTemp(final int itemId) {
		return _map.get(itemId);
	}

	private void load() {

		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;

		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement("select * from z_opqlo_武防升級作業");
			rs = pstm.executeQuery();
			while (rs.next()) {
				final WeaponArmorLV temp = new WeaponArmorLV(rs.getInt("祝福價格"),
						rs.getInt("升級後道具編號"), rs.getInt("升級價格"));
				_map.put(rs.getInt("ItemId"), temp);
			}
		} catch (final SQLException e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(rs, pstm, con);
		}
	}
}
